<?php

	include "kernel.php";
    include "adw_functions.php";

    if ($_POST[dopost]) {

        $file = $_FILES[ffile];


        $strs = file($file[tmp_name]);

        $c = count($strs)-1;
        for ($i=1; $i<=$c; $i++) {

            $str = $strs[$i];
        	$str = ereg_replace("\r","",$str);
        	$str = ereg_replace("\n","",$str);

        	$str = explode(";",$str);

            $line = $str[3];
			$type = $str[1];
            $army = $str[0];

			$rating = $str[2];

        	echo "Lineid: $line ";
            echo "army: $army, type: $type<br>";

            $cc = count($str);
            for ($j=4; $j<$cc; $j++) {
            	$col = $str[$j];

            	echo "Plane:=$col= Id:=".GetPlaneIdByName($col)."=<br>";

                mysql_query("insert into planeset_discr
                (lineid, army, typeOf, rating, planeid, company_id)
                values
                ('$line','$army','$type', '$rating','".GetPlaneIdByName($col)."','".($j-3)."')
                ");


                echo "insert into planeset_discr
                (lineid, army, typeOf, rating, planeid, company_id)
                values
                ('$line','$army','$type', '$rating','".GetPlaneIdByName($col)."','".($j-3)."')
                <br>";

                $check_r = mysql_query("SELECT maxcount from reserv WHERE `company_id`='".($j-3)."' and army='$army' and typeOf='$type' and plane_id='".GetPlaneIdByName($col)."'");

                $check = mysql_fetch_assoc($check_r);

                $check = intval($check['maxcount']);

                if (!$check)
                	echo "<bR><br>ATTENTION!!! THERE ARE NO PLANES '$col'(".GetPlaneIdByName($col).") IN RESERV FOR lineid:$line, comp:".($j-3).", army:$army, typeOf='$type'<br><br>\n";
            }

            echo "<br><br>";
        }

    }

?>

	<form method=post enctype="multipart/form-data">

    <input type=file name=ffile>

	<input type=submit name=dopost value="Add">


	</form>